package com.weixing.mall.provider.controller.front;

import cn.hutool.core.util.StrUtil;
import com.weixing.mall.base.enums.WhetherEnum;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoNeedAccess;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.api.model.enums.ActTypeEnum;
import com.weixing.mall.provider.api.model.enums.GoodsTypeEnum;
import com.weixing.mall.provider.api.model.enums.OrderTypeEnum;
import com.weixing.mall.provider.model.enums.OrderStateEnum;
import com.weixing.mall.provider.model.query.*;
import com.weixing.mall.provider.model.vo.OrderDetilVo;
import com.weixing.mall.provider.service.ILeaderReportService;
import com.weixing.mall.provider.service.IOrderService;
import com.weixing.mall.util.JoddDateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 领导看板接口
 */
@RestController
@RequestMapping("front/leaderShow")
public class FrontLeaderShowController extends BaseController {
    @Autowired
    private ILeaderReportService leaderReportService;
    @Autowired
    private IOrderService orderService;

    /**
     * 领导看板首页汇总信息
     *
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @return
     */
    @ApiOperation("101销售汇总")
    @GetMapping("sale/getReport")
    @NoNeedAccess
    public Result indexDataTotal(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.indexDataTotal(beginDate, endDate));
    }

    /**
     * 领导看板销售总量订单列表(待测试)
     *
     * @return
     */
    @ApiOperation("领导看板销售总量订单列表")
    @GetMapping("sale/getReportList")
    @NoNeedAccess
    public Result orderSaleListForLeader(LeaderShowOrderQuery leaderShowOrderQuery) {
        if (StrUtil.isEmpty(leaderShowOrderQuery.getBeginDate()) || StrUtil.isEmpty(leaderShowOrderQuery.getEndDate())) {
            leaderShowOrderQuery.setBeginDate( JoddDateUtil.parseDateFormat(new Date(),"yyyy-MM")+"-01");
            leaderShowOrderQuery.setEndDate(JoddDateUtil.parseDateFormat(new Date(),"yyyy-MM-dd"));
        }
        return ResultUtil.success(leaderReportService.orderSaleListForLeader(initMPage(),leaderShowOrderQuery));
    }
    /**
     * 领导看板销售额同比（今年和去年）
     *
     * @return
     */
    @ApiOperation("101销售额环比（年）")
    @GetMapping("sale/getSaleHb")
    @NoNeedAccess
    public Result getSaleHb() {
        return ResultUtil.success(leaderReportService.getSaleHb());
    }

    /**
     * 领导看板首页销售额环比（本月和上月）
     *
     * @return
     */
    @ApiOperation("101销售额同比（月）")
    @GetMapping("sale/getSaleTb")
    @NoNeedAccess
    public Result getSaleTb() {
        return ResultUtil.success(leaderReportService.getSaleTb());
    }

    @ApiOperation("101专区销售分布")
    @GetMapping("sale/getZqList")
    public Result getZqList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.getZqList(beginDate, endDate));
    }

    @ApiOperation("101活动销售分布")
    @GetMapping("sale/getActivityList")
    @NoNeedAccess
    public Result getActivityList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        //我也是醉了，一期还是能调整的，二期要是当年的，如果在调整修改即可。
        beginDate= JoddDateUtil.getCurrentYear(new Date())+"-01-01";
        endDate=JoddDateUtil.getCurrentYear(new Date())+"-12-31";
        Map map = new HashMap<String, Object>();
        map.put("agentList", leaderReportService.getActivityList(beginDate, endDate, ActTypeEnum.ACT_AGENT.getValue()));
        map.put("seckillList", leaderReportService.getActivityList(beginDate, endDate, ActTypeEnum.ACT_SECKILL.getValue()));
        return ResultUtil.success(map);
    }

    @ApiOperation(value = "102库存统计")
    @GetMapping(value = "stock/getReport")
    @NoNeedAccess
    public Result getStockReport(LeaderStockQuery leaderStockQuery) {
        return ResultUtil.success(leaderReportService.getStockReport(leaderStockQuery));
    }

    @ApiOperation(value = "102库存列表")
    @GetMapping(value = "stock/getStockList")
    @NoNeedAccess
    public Result getStockList(LeaderStockQuery leaderStockQuery) {
        return ResultUtil.success(leaderReportService.getStockList(initMpPage(), leaderStockQuery));
    }

    @ApiOperation(value = "102库存SKU列表")
    @GetMapping(value = "stock/getStockSkuList")
    @NoNeedAccess
    public Result getStockSkuList(LeaderStockQuery leaderStockQuery) {
        return ResultUtil.success(leaderReportService.getStockSkuList(leaderStockQuery));
    }

    @ApiOperation(value = "102库存类别")
    @GetMapping(value = "stock/getStockType")
    public Result getStockType() {
        return ResultUtil.success(GoodsTypeEnum.values());
    }

    /**
     * 领导看板财物报表销售情况统计
     *
     * @param beginDate 开始时间
     * @param endDate
     * @return
     */
    @ApiOperation("103财务看板-销售统计")
    @GetMapping("financial/getReport")
    @NoNeedAccess
    public Result getReport(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.getReportForFinancial(beginDate, endDate));
    }

    @ApiOperation("103财务看板-商品分类销售额TOP5---修改为TOP20  sql限制修改")
    @GetMapping("financial/getCategorySaleTopFive")
    public Result categorySaleTop5(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.categorySaleTop5(beginDate, endDate));
    }

    /**
     * 领导看板财物报表商品销售额前10
     *
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @return
     */
    @ApiOperation("103财务看板-商品销售额TOP10")
    @GetMapping("financial/getGoodsSaleTopTen")
    @NoNeedAccess
    public Result goodsSaleTop5(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.goodsSaleTop5(beginDate, endDate));
    }

    /**
     * 领导看板财物报表区域销售前5 省份
     *
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @return
     */
    @ApiOperation("103财务看板-区域销售top5：省份")
    @GetMapping("financial/provinceSaleTopFive")
    @NoNeedAccess
    public Result provinceSaleTop10(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.provinceSaleTop10(beginDate, endDate));
    }

    /**
     * 领导看板财物报表区域销售前5 城市
     *
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @return
     */
    @ApiOperation("103财务看板-区域销售top5：城市")
    @GetMapping("financial/citySaleTopfive")
    @NoNeedAccess
    public Result citySaleTop10(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.citySaleTop10(beginDate, endDate));
    }

    /**
     * 领导看板财物报表 区域销售报表
     *
     * @param beginDate 开始时间
     * @param endDate   结束时间
     * @param cityName  城市名称
     * @return
     */
    @ApiOperation("103财务看板-区域销售列表")
    @GetMapping("financial/areaSaleList")
    @NoNeedAccess
    public Result areaSaleList(String beginDate, String endDate, String cityName) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.areaSaleList(initMPage(), beginDate, endDate, cityName));
    }

    @ApiOperation("104发货看板-发货数据统计")
    @GetMapping("shipped/getReport")
    @NoNeedAccess
    public Result getReportForShipped(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.getReportForShipped(beginDate, endDate));
    }

    @ApiOperation("104发货看板-折线图展示发货数量统计")
    @GetMapping("shipped/shippedChart")
    public Result shippedChartTotalList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.shippedChartTotalList(beginDate, endDate));
    }

    @ApiOperation("104发货看板-折线图展示断货数量统计")
    @GetMapping("shipped/outStockChart")
    public Result outStockChartTotalList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.outStockChartTotalList(beginDate, endDate));
    }

    @ApiOperation("104发货看板-折线图展示退货数量统计")
    @GetMapping("shipped/refundedChart")
    public Result refundedChartTotalList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.refundedChartTotalList(beginDate, endDate));
    }

    @ApiOperation("104发货看板-折线图展示取消数量统计")
    @GetMapping("shipped/canceledChart")
    public Result canceledChartTotalList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.canceledChartTotalList(beginDate, endDate));
    }

    @ApiOperation("104发货看板-柱状图展示发货员分区订单数统计----已废弃")
    @GetMapping("shipped/shipperChart")
    public Result shipperPartitionChartTotalList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.shipperPartitionChartTotalList(beginDate, endDate));
    }

    @ApiOperation("104发货看板-列表发货员订单统计")
    @GetMapping("shipped/shipperList")
    public Result shipperTotalList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.shipperTotalList(initMpPage(), beginDate, endDate));
    }

    @ApiOperation(value = "105客服报表统计")
    @GetMapping(value = "kefu/getReport")
    public Result getkefuReport(Long customerId, String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.getKeFuReport(customerId, beginDate, endDate));
    }

    @ApiOperation(value = "105客服有效销售额统计列表")
    @GetMapping(value = "kefu/getSaleList")
    public Result kefuSaleAmountTotalList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.kefuSaleAmountTotalList(beginDate, endDate));
    }

    @ApiOperation(value = "106代理商报表统计")
    @GetMapping(value = "agent/getReport")
    public Result getAgentReport() {
        return ResultUtil.success(leaderReportService.getAgentReport());
    }

    /**
     * 代理商列表
     *
     * @return
     */
    @ApiOperation(value = "代理商列表")
    @GetMapping(value = "agent/teamList")
    @NoNeedAccess
    public Result teamList(LeaderAgentQuery agentQuery) {
        agentQuery.setIsEnable(WhetherEnum.YES.getValue());
        return ResultUtil.success(leaderReportService.teamList(initMPage(),agentQuery));
    }

    /**
     * 代理商续费列表
     *
     * @return
     */
    @ApiOperation(value = "代理商续费列表")
    @GetMapping(value = "agent/agentRenewList")
    @NoNeedAccess
    public Result agentRenewList(LeaderAgentReNewQuery agentQuery) {
        return ResultUtil.success(leaderReportService.agentRenewList(initMPage(),agentQuery));
    }


    @ApiOperation(value = "106代理商报表等级分布")
    @GetMapping(value = "agent/getLevelList")
    public Result agentLevelDistribution() {
        return ResultUtil.success(leaderReportService.agentLevelDistribution());
    }

    @ApiOperation(value = "106代理商报表销售统计")
    @GetMapping(value = "agent/getSaleList")
    public Result getAgentSaleList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.getAgentSaleList(beginDate, endDate));
    }

    @ApiOperation(value = "106代理商报表团队销售统计")
    @GetMapping(value = "agent/getTeamSaleList")
    public Result getTeamSaleList(String beginDate, String endDate) {
        if (StrUtil.isEmpty(beginDate) || StrUtil.isEmpty(endDate)) {
            return ResultUtil.error("日期参数有误");
        }
        return ResultUtil.success(leaderReportService.getTeamSaleList(beginDate, endDate));
    }

    @ApiOperation(value = "106代理商报表地区分布列表")
    @GetMapping(value = "agent/getAreaList")
    public Result getAgentAreaList() {
        return ResultUtil.success(leaderReportService.getAgentAreaList());
    }

    @ApiOperation("107会员报表-会员统计")
    @GetMapping("member/getReport")
    public Result getMemberReport(LeaderMemberQuery leaderMemberQuery) {
        return ResultUtil.success(leaderReportService.getMemberReport(initMpPage(), leaderMemberQuery));
    }

    @ApiOperation("107会员报表-会员统计(新逻辑)")
    @GetMapping("member/getBuyReport")
    @NoNeedAccess
    public Result getBuyReport(LeaderMemberQuery leaderMemberQuery) {
        return ResultUtil.success(leaderReportService.getBuyReport(initMpPage(), leaderMemberQuery));
    }

    /**
     * 会员订单列表
     * @param leaderMemberQuery
     * @return
     */
    @ApiOperation("107会员报表-会员订单列表")
    @GetMapping("member/getBuyList")
    @NoNeedAccess
    public Result getBuyList(LeaderMemberQuery leaderMemberQuery) {
        return ResultUtil.success(leaderReportService.getBuyList(initMpPage(), leaderMemberQuery));
    }
    @ApiOperation("108商品报表-商品销量TOP20")
    @GetMapping("goods/getToplist")
    public Result getGoodsSaleListTop20(String beginDate, String endDate) {
        return ResultUtil.success(leaderReportService.getGoodsSaleListTop20(beginDate, endDate));
    }

    /**sale/getSaleReport
     * 商品销售详情，按照商品进行分组
     * @param leaderGoodsQuery
     * @return
     */
    @ApiOperation("108商品报表-商品销售报表")
    @GetMapping("goods/getSaleList")
    @NoNeedAccess
    public Result getGoodsSaleList(LeaderGoodsQuery leaderGoodsQuery) {
        return ResultUtil.success(leaderReportService.getGoodsSaleList(initMpPage(), leaderGoodsQuery));
    }
    /**
     * 商品销售详情，按照商品进行分组  显示最近6个月的数据
     * @return
     */
    @ApiOperation("108商品报表-商品销售报表")
    @GetMapping("goods/getSaleFxList")
    @NoNeedAccess
    public Result getSaleFxList() {
        return ResultUtil.success(leaderReportService.getSaleFxList());
    }
    /**
     * 根据商品id查找货品的售卖情况
     * @param leaderGoodsQuery
     * @return
     */
    @ApiOperation("108商品报表-根据商品id查找货品的售卖情况")
    @GetMapping("goods/getSaleSKuList")
    @NoNeedAccess
    public Result getSaleSKuList(LeaderGoodsQuery leaderGoodsQuery) {
        return ResultUtil.success(leaderReportService.getSaleSKuList(leaderGoodsQuery));
    }
    @ApiOperation(value = "108订单类型")
    @GetMapping(value = "goods/getOrderType")
    public Result getOrderType() {
        return ResultUtil.success(OrderTypeEnum.values());
    }

    /**
     * 销售报表合计情况
     *
     * @param leaderSaleQuery
     * @return
     */
    @ApiOperation("109销售报表-销售数量和金额统计")
    @GetMapping("sale/getSaleReport")
    @NoNeedAccess
    public Result getSaleReport(LeaderSaleQuery leaderSaleQuery) {
        return ResultUtil.success(leaderReportService.getSaleReport(leaderSaleQuery));
    }

    /**
     * 销售报表个人列表
     *
     * @param leaderSaleQuery
     * @return
     */
    @ApiOperation("109销售报表-个人销售统计列表")
    @GetMapping("sale/getPersonalList")
    @NoNeedAccess
    public Result personalSaleReportList(LeaderSaleQuery leaderSaleQuery) {
        //leaderSaleQuery.setOrderStatus(OrderStateEnum.REJECT);
        return ResultUtil.success(leaderReportService.personalSaleReportList(initMpPage(), leaderSaleQuery));
    }

    /**
     * 销售报表团队列表
     *
     * @param leaderSaleQuery
     * @return
     */
    @ApiOperation("109销售报表-团队销售统计列表")
    @GetMapping("sale/getTeamList")
    @NoNeedAccess
    public Result teamSaleReportList(LeaderSaleQuery leaderSaleQuery) {
        //leaderSaleQuery.setOrderStatus(OrderStateEnum.REJECT);
        return ResultUtil.success(leaderReportService.teamSaleReportList(initMpPage(), leaderSaleQuery));
    }

    /**
     * 可以查询额活动列表
     *
     * @param type
     * @return
     */
    @ApiOperation("以查询活动列表")
    @GetMapping("sale/actList")
    @NoNeedAccess
    public Result actList(ActTypeEnum type) {
        //leaderSaleQuery.setOrderStatus(OrderStateEnum.REJECT);
        return ResultUtil.success(leaderReportService.actList(type.getValue()));
    }

    /**
     * 通过销售报表的实际销售量进行订单列表的下探
     *
     * @param leaderSaleQuery
     * @return
     */
    @ApiOperation("通过销售报表的实际销售量进行订单列表的下探")
    @GetMapping("sale/saleReportOrderList")
    @NoNeedAccess
    public Result saleReportOrderList(LeaderSaleOrderListQuery leaderSaleQuery) {
        //leaderSaleQuery.setOrderStatus(OrderStateEnum.REJECT);
        return ResultUtil.success(leaderReportService.saleReportOrderList(initMpPage(), leaderSaleQuery));
    }

    /**
     * 查看订单详情
     *
     * @param id 订单id
     * @return 订单详情
     */
    @GetMapping("/getOrderDetails/{id}")
    @NoNeedAccess
    public Result<OrderDetilVo> getOrderDetails(@PathVariable long id) {
        OrderDetilVo orderDetilVo = orderService.selectOrderDetails(id);
        return ResultUtil.success(orderDetilVo);
    }

    /**
     * 广告标签
     *
     * @return 订单详情
     */
    @GetMapping("/adsLabel")
    @NoNeedAccess
    public Result adsLabel() {
        return ResultUtil.success(leaderReportService.adsLabel());
    }

    /**
     * 广告标签
     *
     * @return 订单详情
     */
    @GetMapping("/agentList")
    @NoNeedAccess
    public Result agentList() {
        return ResultUtil.success(leaderReportService.getAgentRootList());
    }

}
